package com.indusfo.spc.controller;

import com.indusfo.spc.aspect.SystemControllerLog;
import com.indusfo.spc.pojo.Maintain;
import com.indusfo.spc.service.MaintainService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 设备保养项目控制层
 */

@Controller
@RequestMapping("/service/maintain")
public class MaintainController {

    @Autowired
    private MaintainService maintainService;
    
    /**
     * 编辑
     *
     * @param maintain
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value = "/updateMaintain",method= RequestMethod.POST)
    @SystemControllerLog(description="编辑保养项目")
    @ResponseBody
    public JSONObject updateMaintain (Maintain maintain){
        JSONObject json=maintainService.updateMaintain(maintain);
        return json;
    }

    /**
     * 查询
     *
     * @param maintain
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/queryMaintain")
    @SystemControllerLog(description="查询保养项目")
    @ResponseBody
    public JSONObject queryMaintain(Maintain maintain) {
        JSONObject json = maintainService.selectAll(maintain);
        return json;

    }

    /**
     * 新增
     *
     * @param maintain
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/insertMaintain", method= RequestMethod.POST)
    @SystemControllerLog(description="新增保养项目")
    @ResponseBody
    public JSONObject insertMaintain(Maintain maintain) {
        JSONObject json = maintainService.insertMaintain(maintain);
        return json;
    }

    /**
     * 启用/停用
     *
     * @param maintainIds, dataState
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/definedMaintain", method= RequestMethod.POST)
    @SystemControllerLog(description="启用/停用保养项目")
    @ResponseBody
    public JSONObject definedMaintain(Long[] maintainIds, Integer dataState) {
        JSONObject json = maintainService.definedMaintain(maintainIds, dataState);
        return json;
    }

    /**
     * 删除
     *
     * @param maintainIds, dataState
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/deleteMaintain", method= RequestMethod.POST)
    @SystemControllerLog(description="删除保养项目")
    @ResponseBody
    public JSONObject deleteMaintain(Long[] maintainIds, Integer dataState) {
        dataState = 2;
        JSONObject json = maintainService.definedMaintain(maintainIds, dataState);
        return json;
    }
    
}
